// index.js
import {userStore} from "../../store/index"
Page({
  data:{
    getUserInfo:false,
    msg:[]
  },
  onLoad(){
    this.setupUserStore()
  },
  loginHandle(){
    let userInfo = {}
    if(!this.data.getUserInfo){
      wx.getUserProfile({
        desc: '同步微信昵称',
        success:res=>{
          userInfo["nickName"] = res.userInfo.nickName
          userInfo["avatarUrl"] = res.userInfo.avatarUrl  
          userStore.dispatch("_getUserProfile",{userInfo})
          wx.navigateTo({
            url: '../teamChat/index',
          })
          this.setData({getUserInfo:true})
        }
      })
    }else{
      wx.navigateTo({
        url: '../teamChat/index',
      })
    }
  },
  delMsgHandle(){
    if(this.data.msg.length!==0 && this.data.msg.length!==1) {
      wx.showToast({
        title: '清除成功',
        duration:2000
      })
      userStore.dispatch("_delMsg")
    }
      else {
        wx.showToast({
          title: '没有消息记录',
          icon:"none",
          duration:2000
        })
    }
  },
  setupUserStore(){
    userStore.onStates(["msg"],({msg})=>{
      this.setData({msg})
    })
  }
})
